<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="/WEB-INF/views/include/taglib.jsp"%>
<html>
<head>
    <title>客户区域列表</title>
    <meta name="decorator" content="default"/>
    <link rel="stylesheet" href="${ctxStatic}/bootstrap-table/bootstrap-table.css">
    <script src="${ctxStatic}/bootstrap-table/bootstrap-table.js"></script>
    <script src="${ctxStatic}/bootstrap-table/locale/bootstrap-table-zh-CN.js"></script>
    <script src="${ctxStatic}/bootstrap-table/config.js"></script>
</head>
<body>
	<ul class="nav nav-tabs">
	    <!--默认不跳转-->
		<li class="active"><a href="javascript:void(0);">客户区域列表</a></li>
        <shiro:hasPermission name="sys:region:edit"><li><a href="${ctx}/sys/region/form">客户区域添加</a></li></shiro:hasPermission>
        <li><a href="${ctx}/sys/region/listAdmin">固定区域列表</a></li>
	</ul>
    <form id="searchForm" action="${ctx}/sys/region/listAjaxData" method="post" class="breadcrumb form-search">
        <ul class="ul-form">
            <ul class="ul-form">
                <li>
                    <div class="input-prepend">
                        <span class="add-on">名称</span>
                        <input name="regionName" type="text" class="input-medium" placeholder="请输入名称"/>
                    </div>
                </li>
                <li class="btns">
                    <button id="search" class="btn btn-small btn-primary" type="button">
                        查询<span class="icon-search icon-white"></span>
                    </button>
                </li>
                <li class="clearfix"></li>
            </ul>
        </ul>
    </form>

	<table id="contentTable" data-url="${ctx}/sys/region/listAjaxData">
        <thead>
        <tr>
            <th data-field="state" data-align="center" data-formatter="indexFormatter">序号</th>
            <th data-field="regionName"  data-align="center">名称</th>
            <th data-field="sortOrder"  data-align="center">排序</th>
            <th data-field="dateCreated"  data-align="center">创建时间</th>
            <th data-field="lastUpdated"  data-align="center">修改时间</th>
            <th data-field="operate" data-align="left" data-formatter="operateFormatter" data-events="operateEvents" >操作</th>
        </tr>
        </thead>
	</table>
    <script type="text/javascript">
        $(document).ready(function() {
            closeTip();
            $("#contentTable").bootstrapTable(
                $.fn.BTConfigSimple({
                    pageList: [30, 50, 100],
                    pageSize: 30,
                    sortName: "regionName",
                    userQuery:function(){
                        return $('#searchForm').refreshByForm().query;
                    }
                }));
            $("#search").click(function () {
                refresh();
            });
        });
        //全局函数部分
        function refresh(){
            $("#contentTable").bootstrapTable(
                'refresh',
                $("#searchForm").refreshByForm());
        }

        function operateFormatter(value, row, index){
            var array = [];
            array.push('<a class="edit" href="${ctx}/sys/region/form?id='+row.id+'" title="编辑/查看">');
            array.push('<i class="icon icon-edit"></i>');
            array.push('</a>');
            <shiro:hasPermission name="sys:region:edit">
                array.push('  ');
                array.push('<a class="remove" href="javascript:void(0)" title="删除">');
                array.push('<i class="icon icon-remove"></i>');
                array.push('</a>');
            </shiro:hasPermission>
            return array.join('');
        }
        function indexFormatter(value, row, index){
            return index +1;
        }

        var operateEvents = {
            'click .remove': function (e, value, row, index) {
                confirmx("您确认要删除记录[" + row.regionName + "]?",
                function () {
                    $.ajax({
                        url: "${ctx}/sys/region/delete",
                        type: "post",
                        data: {id: row.id},
                        dataType: "json",
                        success: function (data) {
                            if (data.state == true) {
                            showTip(data.message);
                            refresh();
                        } else {
                            alertx(data.message);
                        }
                        },
                        error: function (data, state, error) {
                            alertx(data.responseText, null, '请求错误');
                        }
                    });});
            }
        };

    </script>
</body>
</html>